package org.jg.arkanoid.bonuses;

import java.awt.Color;

import org.jg.arkanoid.gameobjects.Carriage;
import org.jg.arkanoid.gameobjects.GameObject;
import org.jg.arkanoid.gameobjects.GunBullet;
import org.jg.arkanoid.util.Vector;

public class Guns extends GameObject implements Bonus{
	
	private int capcity;
	private Carriage carriage;
	
	private int width;
	private int height;
	
	private Vector bulletVelocity;
	private int bulletHeight;
	private int bulletWidth;
	
	public Guns( Carriage carriage )
	{
		this.carriage = carriage;
		
		bulletVelocity = new Vector(0, 10);
		bulletHeight = 5;
		bulletWidth = 3;
		
		width = bulletWidth; 
		height = (int) (bulletHeight*1.5);
	}
	
	public Vector getPosition()
	{
		if( carriage == null )
		{
			return null;
		}
		
		Vector carriagePosition = carriage.getPosition();
		int carriadgeWidth = carriage.getWidth();
		
		int gunPosX = (int) (carriagePosition.getX() + carriadgeWidth/2 - width/2);
		int gunPosY = (int) (carriagePosition.getY() - height);
		
		Vector gunPosition = new Vector(gunPosX, gunPosY);
		
		return gunPosition;
	}
	
	public void fire()
	{
		if(color != Color.DARK_GRAY)
			color = Color.DARK_GRAY;
		else
			color = Color.LIGHT_GRAY;
		
		if(capcity <= 0)
			return;
	}
	
	@Override
	public boolean isCollidable()
	{
		return false;
	}
	
	private GunBullet createBullet()
	{
		GunBullet bullet = new GunBullet();
		
		Vector bulletStart = carriage.getPosition().addVector(carriage.getWidth()/2, bulletHeight + 1);
		bullet.setPosition(bulletStart);
		
		bullet.setVelocity(bulletVelocity);
		
		return bullet;
	}
	
}
